<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="format-detection" content="email=no"/>
    <meta charset="UTF-8">
    <script type="text/javascript" th:src="@{${session.baseUrl}+'js/common.js'}"></script>
    <script th:src="@{${session.baseUrl}+'js/jquery.js'}"></script>
    <link th:href="@{${session.baseUrl}+'style/reset.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/base.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/header.css'}" rel="stylesheet" type="text/css">
    <link rel="stylesheet" th:href="@{${session.baseUrl}+'style/phone.css'}"/>
    <link th:href="@{${session.baseUrl}+'style/dialog.css'}" rel="stylesheet" type="text/css">
    <link th:href="@{${session.baseUrl}+'style/global.css'}" rel="stylesheet" type="text/css">
    <script th:src="@{${session.baseUrl}+'js/dialog.js'}"></script>
    <title>申请代理</title>
    <style>
        .sub {
            display: block;
            width: 6.3rem;
            line-height: 0.77rem;
            font-size: 0.26rem;
            color: #fff;
            background: #2d9cff;
            margin: 2% auto;
            border-radius: 0.1rem;
        }
    </style>
</head>
<body>
<header><span onclick="javascript:history.go(-1)"></span>申请代理</header>

<div id="maildiv">
        <ul>

            <li><input id="phone" type="text" style="height: 1rem" name="phone" maxlength="11" placeholder="请输入接受通知的手机号" onblur="phoneyanzheng()"/></li>
            <li><span id="span" style="font-size: 20px"></span></li>
            <li><input class="sub" type="button" value="申请" onclick="shenli()"/></li>

        </ul>
    <input id="num" type="hidden">
</div>

<script type="text/javascript" th:inline="javascript">
    var basePath = /*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/;


    var pflag = 2;

    //手机号码验证
    function phoneyanzheng() {
        var namespan = $("#span");
        var newphone = $("#phone").val();
        if (newphone == '') {
            namespan.html('手机号不能为空').css('color', '#ff2525');
            pflag = 2;
        } else if (!(/^1[3456789]\d{9}$/.test(newphone))) {
            namespan.html('手机号不正确').css('color', '#ff2525');
            pflag = 3;
        } else {
            namespan.html(' ');
            pflag = 1;
        }

    }

    function shenli() {

            var userId=/*[[${user.id}]]*/;
            var userName=/*[[${user.name}]]*/;
            if(pflag==1){
                $.ajax({
                    url: "/invitationApplication/add2",
                    type: "POST",
                    dataType: "json",
                    data:JSON.stringify({
                        memberId:userId,
                        memberName:userName,
                        phone:$("#phone").val()
                    }),
                    contentType : 'application/json',
                    success: function (e) {

                        if (e.data){
                            $('body').dailog({type:'success',title:'成功',discription:'申请已提交，等待审核，审核结果另行通知。'});
                            self.setInterval(function(){  // 这个方法是说在延迟3秒后执行大括号里的方法
                                window.location.href=basePath+"/wap/personal.html"
                            },3000) //这里3000代表3秒
                        }else {
                            $('body').dailog({type:'danger',title:'失败',discription:'申请提交失败，请重新提交'});
                            self.setInterval(function(){  // 这个方法是说在延迟3秒后执行大括号里的方法
                                window.location.href=basePath+"/wap/personal.html"
                            },3000) //这里3000代表3秒
                        }
                    }
                })
            }else if(pflag==2){
                $("#span").html('请先填写手机号').css('color', '#ff2525');
            }else if(pflag==3){
                $("#span").html('请填写正确手机号').css('color', '#ff2525');
            }
        }




</script>
</body>
</html>